import request from '@/utils/request';

// 用户登录
export const login = (data) => {
  return request({
    url: '/auth/login',
    method: 'post',
    data
  });
};

// 用户注册
export const register = (data) => {
  return request({
    url: '/auth/register',
    method: 'post',
    data
  });
};

// 发送验证码
export const sendVerifyCode = (phone) => {
  return request({
    url: '/auth/sendVerifyCode',
    method: 'post',
    data: { phone }
  });
};

// 实名认证
export const submitAuth = (data) => {
  // 创建 FormData 对象
  const formData = new FormData();
  formData.append('realName', data.realName);
  formData.append('idNumber', data.idNumber);
  
  // 添加文件
  if (data.idCardFront.length > 0) {
    formData.append('idCardFront', data.idCardFront[0].file);
  }
  if (data.idCardBack.length > 0) {
    formData.append('idCardBack', data.idCardBack[0].file);
  }
  if (data.signature.length > 0) {
    formData.append('signature', data.signature[0].file);
  }

  return request({
    url: '/user/auth',
    method: 'post',
    data: formData
  });
};

// 获取用户信息
export const getUserInfo = () => {
  return request({
    url: '/user',
    method: 'get'
  });
};

// 获取指定用户信息
export const getUserById = (id) => {
  return request({
    url: `/user/${id}`,
    method: 'get'
  });
}; 